package top.kikt.book.util

import org.junit.Assert.*

class HttpUtilsTest {

    @org.junit.Test
    fun decodeCurlCommandHeaders() {
        val cmd = """curl 'https://www.23usp.com/xs_4680/' \
              -H 'authority: www.23usp.com' \
              -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
              -H 'accept-language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6' \
              -H 'cache-control: max-age=0' \
              -H 'cookie: Hm_lvt_f9ae6265784e39ff3e9123e3c13eee02=1672628703; SL_G_WPT_TO=zh-CN; SL_GWPT_Show_Hide_tmp=1; SL_wptGlobTipTmp=1; Hm_lpvt_f9ae6265784e39ff3e9123e3c13eee02=1672628936' \
              -H 'referer: https://www.23usp.com/quanbuxiaoshuo/' \
              -H 'sec-ch-ua: "Not?A_Brand";v="8", "Chromium";v="108", "Microsoft Edge";v="108"' \
              -H 'sec-ch-ua-mobile: ?0' \
              -H 'sec-ch-ua-platform: "macOS"' \
              -H 'sec-fetch-dest: document' \
              -H 'sec-fetch-mode: navigate' \
              -H 'sec-fetch-site: same-origin' \
              -H 'sec-fetch-user: ?1' \
              -H 'upgrade-insecure-requests: 1' \
              -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 Edg/108.0.1462.54' \
              --compressed
        """.trimIndent()

        val map = HttpUtils.decodeCurlCommandHeaders(cmd)
        assertEquals(15, map.size)

        assertEquals("www.23usp.com", map["authority"])
        assertEquals("https://www.23usp.com/quanbuxiaoshuo/", map["referer"])
    }
}